# 1 给定两个字符串 s 和 t 判断 t 是否为 s 重新排列后组成的单词
#   s = anagram     t = anagram   --->true
#   ord(c)  将c转换成ASCII码 a-z 97-122

import cal_time,time
# def word(s,t):
#     bucket1 = [[] for _ in range(26)]
#     bucket2 = [[] for _ in range(26)]
#     for each in s:
#         bucket_index = ord(each) - 97
#         bucket1[bucket_index].append(each)
#     for each in t:
#         bucket_index = ord(each) - 97
#         bucket2[bucket_index].append(each)
#     if bucket1 == bucket2:
#         return True
#     else:
#         return False
# print(word("anagram", "anagram"))
# print(word("rat", "cat"))
#
# def isAnagram(s,t):
#
#     ss = list(s)
#     tt = list(t)
#     ss.sort()
#     tt.sort()
#     if ss == tt:
#         return True
#     else:
#         return False
# print(word("anagram", "anagram"))
# print(word("rat", "cat"))

# 2 给定一个 m*n 的二位列表，查找一个数是否存在。列表特征：1 每一行从左到右已经拍好，2 每一行第一个数比上一行最后一个数大



def searchMatrix(matrix,target):
    h = len(matrix)
    if h == 0:
        return False
    w = len(matrix[0])
    if w == 0:
        return True
    left = 0
    right = w * h - 1
    while left<=right:
        mid = (left+right) //2
        h_index = mid // h
        w_index = mid % w
        if matrix[h_index][w_index] == target:
            return True
        elif matrix[h_index][w_index] < target:
            left = mid + 1
        else:
            right = mid - 1
    else:
        return False

matrix = [
    [1,3,5,7],
    [10,11,16,20],
    [23,30,34,50],
]
print(searchMatrix(matrix, 11))

"""

"""